@extends('admin.base')
	@section('content')
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            商品信息表
            <small>mall informations of simple tables</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="{{url('admin')}}"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">商品信息</a></li>
            <li class="active">列表</li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
				<div class="col-md-12">
				  <div class="box">
					<div class="box-header with-border">
					  <h3 class="box-title"><i class="fa fa-th"></i> 商品信息管理</h3>
						<div class="box-tools">
							<form action="{{url('admin/minfo')}}" method="get">
								<div class="input-group" style="width: 150px;">
										<input type="text" name="name" class="form-control input-sm pull-right" placeholder="查询商品"/>
									<div class="input-group-btn">
										<button class="btn btn-sm btn-default"><i class="fa fa-search"></i></button>
									</div>
								</div>
							</form>
						</div>
					</div><!-- /.box-header -->
					<div class="box-body">
					  <table class="table table-bordered">
						<tr>
						  <th>编号</th>
						  <th style="width:50px;">所属类别</th>
						  <th>名称</th>
						  <th>相关配置</th>
						  <th>价格</th>
						  <th>货存</th>
						  <th>点击量</th>
						  <th>状态</th>
						  <th>图片</th>
						  <th style="width:100px;">操作</th>
						</tr>
						@foreach($list1 as $minfo)
						<tr>
							@foreach($list as $search)
							@if($minfo->mid==$search->mid)
							<td>{{$minfo->mid}}</td>
							@endif
							@endforeach
							
							@foreach($list as $search)
							@if($minfo->mid==$search->mid)
								@foreach($list2 as $genre)
								@if($genre->id == $minfo->gid)
							<td>{{$genre->name}}</td>
								@endif
								@endforeach
							@endif
							@endforeach
							
							@foreach($list as $search)
							@if($minfo->mid==$search->mid)
							<td><abbr title="{{$minfo->brief}}">{{$minfo->name}}</abbr></td>
							@endif
							@endforeach
							
							@foreach($list as $search)
							@if($minfo->mid==$search->mid)
								<td>
								@foreach($list3 as $pag)
								@if($search->gid == $pag->gid && $pag->name != "价格")
									<?php 
										/**
											将数据库中标签表中对应的标签遍历出来
											$n（标签表中的field）等于 商品搜索表中的搜索字段
											$field（商品搜索表中字段指向的该商品信息） 等同于 $search->搜索字段
										*/
										$n = ($pag->field);
										$field = $search->$n;?>
									<abbr title="{{$pag->name}}">{{$field}}</abbr>&nbsp;&nbsp;
								@endif
								@endforeach
								</td>
							@endif
							@endforeach

							@foreach($list as $search)
							@if($minfo->mid==$search->mid)
							<td>{{$search->price}}</td>
							@endif
							@endforeach
							
							@foreach($list as $search)
							@if($minfo->mid==$search->mid)
							<td><abbr title="已卖出{{$minfo->sale}}">{{$minfo->number}}</abbr></td>
							@endif
							@endforeach
							
							@foreach($list as $search)
							@if($minfo->mid==$search->mid)
							<td>{{$minfo->comeclick}}</td>
							@endif
							@endforeach

							@foreach($list as $search)
							@if($minfo->mid==$search->mid)
								@if($minfo->status === 'on')
								<td>热卖</td>
								@elseif($minfo->status === 'off')
								<td>下架</td>
								@else
								<td>新款</td>
								@endif
							@endif
							@endforeach
							
							@foreach($list as $search)
							@if($minfo->mid==$search->mid)
							<td width="5px"><a href='{{url("admin/pic/$minfo->mid")}}' class="btn btn-xs btn-danger">浏览</a> </td>
							@endif
							@endforeach

							@foreach($list as $search)
							@if($minfo->mid==$search->mid)
							<td><button onclick="doDel({{$minfo->mid}});" class="btn btn-xs btn-danger">删除</button> 
								  <a href='{{url("admin/minfo/$minfo->mid/edit")}}' class="btn btn-xs btn-primary">编辑</a></td>
							@endif
							@endforeach
						</tr>
						@endforeach
						</table>
						<form id="mydeleteform" method="post">
							<input type="hidden" name="_method" value="delete">
							<input type="hidden" name="_token" value="{{ csrf_token() }}">
						</form>
						</div><!-- /.box-body -->
						<div class="box-footer clearfix">
							{!! $list1->appends($params)->render() !!}
						</div> 
					</div><!-- /.box -->
				</div><!-- /.col -->
			</div><!-- /.row -->
        </section><!-- /.content -->
    @endsection
	
	<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="exampleModalLabel">New message</h4>
          </div>
          <div class="modal-body">
           <!-- 此处填充 -->
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button type="button" onclick="saveType()" class="btn btn-primary">添加</button>
          </div>
        </div>
      </div>
    </div>
	@section("myscript")
	<script type="text/javascript">
		function doDel(id){
            Modal.confirm({msg:'是否删除此类别？'}).on(function (e){
                if(e){
                    var form = document.getElementById("mydeleteform");
                    form.action = "{{URL('/admin/minfo')}}/"+id;
                    form.submit(); 
                }
            });
        }
	</script>
	@endsection